//
//  DatePickerDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/7/1.
//

import SwiftUI

struct DatePickerDemo: View {
    
    @State var selectedDate: Date = Date()
    
    let startingDate: Date = Calendar.current.date(from: DateComponents(year: 2025, month: 1, day: 1)) ?? Date()
    let endingDate: Date = Date()
    
    var dateFormatter: DateFormatter {
        let formatter = DateFormatter()
        formatter.dateStyle = .medium
        formatter.timeStyle = .short
        return formatter
    }
    
    var body: some View {
        
        VStack {
            Text("Selected Date is:")
            Text(dateFormatter.string(from: selectedDate))
                .font(.title)
        
        
//        DatePicker("Select a Date", selection: $selectedDate)
//        DatePicker("Select a Date", selection: $selectedDate, displayedComponents: [.date, .hourAndMinute])
        DatePicker("Select a Date", selection: $selectedDate, in: startingDate...endingDate, displayedComponents: [.date])
//            .padding()
            .accentColor(.red)
            .datePickerStyle(CompactDatePickerStyle())
//            .datePickerStyle(GraphicalDatePickerStyle())
//            .datePickerStyle(WheelDatePickerStyle())
        }
    }
}

#Preview {
    DatePickerDemo()
}
